package util.zip;

import org.junit.Test;

import java.io.*;
import java.util.HashMap;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

/**
 * @author LiDong
 * @version 1.0.0
 * @createTime 2/10/2023 2:33 PM
 */
public class ZipTest {

    @Test
    public void test1() throws IOException {
        File file = new File("C:/Users/root/Desktop/test1.zip");
        File file1 = new File("C:/Users/root/Desktop/test1.zip");
        //取出文件名
        String name = file.getName();
        //读取文件
        FileInputStream inputStream = new FileInputStream(file);

        Map<String,Object> map = new HashMap<>();
        map.put("测试文件夹1",inputStream);
        map.put("测试文件夹2",inputStream);

        //输出流
        ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream("C:/Users/root/Desktop/test2.zip"));


        //ZipEnter:表示压缩文件的条目(文件目录)
        zipOutputStream.putNextEntry(new ZipEntry("测试文件夹1\\"));
        zipOutputStream.putNextEntry(new ZipEntry("测试文件夹2\\"));

        int temp = 0;
        while ((temp = inputStream.read()) != -1) {
            zipOutputStream.write(temp);
        }
        zipOutputStream.close();
        inputStream.close();


    }
}
